--- title: "武士风度的牛" created: 2025-11-28 tags: - 算法 --- # 武士风度的牛 ## 题目 [武士风度的牛](https://www.acwing.com/problem/content/190/) ![[image-491b2ac9.png]] ## 思路分析 已经大成了 照着模版默 一遍过 甚至没有debug的过程 ## 代码实现 ```cpp #include using namespace std; #define endl '\n' typedef pair PII; const int N=160; int n,m; char g[N][N]; int d[N][N]; int startx,starty,targetx,targety; int dx[8]={-2,-1,1,2,2,1,-1,-2}; int dy[8]={1,2,2,1,-1,-2,-2,-1}; bool isVaild(int x,int y){ return x>=0 && x<=n-1 && y>=0 && y<=m-1 && d[x][y]==-1; } void bfs(int x,int y){ queue q; memset(d,-1,sizeof d); q.push({x,y}); d[x][y]=0; while(!q.empty()){ auto cur=q.front();q.pop(); int ux=cur.first,uy=cur.second; if(ux==targetx && uy==targety){ cout<>m>>n; for(int i=0;i>g[i]; } for(int i=0;i